package concurrent.cas;


import lombok.SneakyThrows;
import sun.misc.Unsafe;

import java.lang.reflect.Field;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicStampedReference;

public class CasTest {
    static AtomicInteger atomicInteger = new AtomicInteger(100);
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                atomicInteger.compareAndSet(100, 200);
                atomicInteger.compareAndSet(200, 100);
            }
        });

        Thread thread1 = new Thread(new Runnable() {
            @SneakyThrows
            @Override
            public void run() {
                Thread.sleep(2000);
                boolean b = atomicInteger.compareAndSet(100, 200);
                System.out.println(b);
            }
        });
        thread.start();
        thread1.start();
    }
}
